How To Build GCC/G++ 4.3.3 AVR 32-bit Cross-Compiler
Intro
In this How To we are going to build an ARM cross-compiler based upon GCC/G++ 4.3.3. Before you begin you might want to take a look at my build machine specs to get an idea of what I'm running on compared to your machine. In the least please make sure you have enough memory. Do not expect a flawless build, especially if you are only running with 1 to 2 GB of memory 8P If you run into issues try to figure them out.
Why would I want to do this you ask? Especially when there are numerous tools/scripts out there that do it for you!? First of all, I can use this to play on the newest Arduino SBC - Arduino Zero! Second, there are too many tools/scripts out there that do this for you. I want to learn how to do this myself, so I'm not "vendor locked" to one of these tools ;-P
Tar Balls
Here is a list of source packages that we'll need for the build. You can either download them now or wait 'til later in the How To.
binutils-2.20.1.tar.bz2
glibc-2.9.tar.gz
glibc-ports-2.9.tar.bz2
gcc-4.3.3.tar.gz
gmp-4.3.1.tar.bz2
mpfr-2.4.1.tar.bz2
linux-2.6.38.tar.bz2
atmel patches for binutils-2.20.1
atmel patches for gcc-4.3.3
Create a Workspace
I recommend creating a workspace under your /home/<your user>/ directory that is dedicated to this build. So let's fire up your terminal and run the following:
I recommend making a patchset for the above patches before continuing. Now apply the patches:
$ cd $SRCDIR/binutils-2.20.1/
$ for patch in `cat ../../atmel-patches/binutils-2.20.1/patchset`; do patch -Np0 -i ../../atmel-patches/binutils-2.20.1/$patch; done
Check the output from the above command to make sure there was no error. If you get an error make sure you are in the correct directory when running patch.
Now that we modified some of the source files in binutils-2.20.1 we need to re-generate some configure scripts. We do this by running automake and autoreconf. But before that we need to make a change to override.m4 in $SRCDIR/binutils-2.20.1/config. Open this file in your favorite text editor and look for the following line:
...
...
dnl Ensure exactly this Autoconf version is used
m4_ifndef([_GCC_AUTOCONF_VERSION],
[m4_define([_GCC_AUTOCONF_VERSION], [2.64])])
...
...
Change 2.64 to your autoconf version. For me, it is 2.69:
$ autoconf -V
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David J. MacKenzie and Akim Demaille.
Now we can run automake and autoreconf in binutils-2.20.1 source directory and *all* of its subdirectories. Some of the subdirectories do not need them, but I'll let you experience that for yourself ;P You'll get some output from the automake and autoreconf about the command failing, configure.in should be called configure.ac and the like. You can safely ignore all of this. This most important part is that you run both commands in binutils-2.20.1 source directory and *all* of its subdirectories.
$ mkdir -pv $BUILDDIR
$ mkdir -pv $BUILDDIR/binutils
$ cd $BUILDDIR/binutils
$ $BINUTILS_SRC/configure --disable-werror --build=$BUILDMACH --target=$TARGETMACH --prefix=$INSTALLDIR --with-sysroot=$SYSROOTDIR
$ make
# When the build fails run:
$ make -C bfd headers && make
$ make install
Kernel Headers
$ cd $KERNEL_SRC
$ make mrproper
$ make ARCH=avr32 favr-32_defconfig
$ mkdir -pv $INSTALLDIR/sysroot/usr
$ make ARCH=avr32 headers_check
$ make ARCH=avr32 INSTALL_HDR_PATH=$INSTALLDIR/sysroot/usr headers_install
$ cd $SRCDIR
Feel free to substitute any of the config files found in ../src/linux-2.6.38/arch/avr32/configs for make ARCH=
Bootstrap gcc
Before we can start building bootstrap gcc we need to make a change to ../src/gcc-4.3.3/libgcc/config.host:
Change this line
How To Build GCC/G++ 4.3.3 AVR 32-bit Cross-Compiler
Intro
In this How To we are going to build an ARM cross-compiler based upon GCC/G++ 4.3.3. Before you begin you might want to take a look at my build machine specs to get an idea of what I'm running on compared to your machine. In the least please make sure you have enough memory. Do not expect a flawless build, especially if you are only running with 1 to 2 GB of memory 8P If you run into issues try to figure them out.
Why would I want to do this you ask? Especially when there are numerous tools/scripts out there that do it for you!? First of all, I can use this to play on the newest Arduino SBC - Arduino Zero! Second, there are too many tools/scripts out there that do this for you. I want to learn how to do this myself, so I'm not "vendor locked" to one of these tools ;-P
Tar Balls
Here is a list of source packages that we'll need for the build. You can either download them now or wait 'til later in the How To.
Create a Workspace
I recommend creating a workspace under your /home/<your user>/ directory that is dedicated to this build. So let's fire up your terminal and run the following:
Gather the Sources
Now that we have a workspace created and we are currently in the src directory we can begin bringing down the sources and extracting them.
binutils
glibc
gcc
kernel
binutils - atmel patch
I recommend making a patchset for the above patches before continuing. Now apply the patches:Check the output from the above command to make sure there was no error. If you get an error make sure you are in the correct directory when running patch.
Now that we modified some of the source files in binutils-2.20.1 we need to re-generate some configure scripts. We do this by running automake and autoreconf. But before that we need to make a change to override.m4 in $SRCDIR/binutils-2.20.1/config. Open this file in your favorite text editor and look for the following line:
Change 2.64 to your autoconf version. For me, it is 2.69:
Now we can run automake and autoreconf in binutils-2.20.1 source directory and *all* of its subdirectories. Some of the subdirectories do not need them, but I'll let you experience that for yourself ;P You'll get some output from the automake and autoreconf about the command failing, configure.in should be called configure.ac and the like. You can safely ignore all of this. This most important part is that you run both commands in binutils-2.20.1 source directory and *all* of its subdirectories.
gcc-4.3.3 - atmel patch
I recommend making a patchset for the above patches before continuing. Now apply the patches:As we did previously with binutils; you'll need to run automake and autoreconf in gcc-4.3.3 source directory and *all* of its subdirectories.
Phew! If you got this far, give yourself another cold glass of Mountain Dew and let's keep going 8-D
Build Environment
To make things a little smoother let's setup some environment variables:
Next up is to begin building.
Build binutils
Kernel Headers
Feel free to substitute any of the config files found in ../src/linux-2.6.38/arch/avr32/configs for make ARCH=
Bootstrap gcc
Before we can start building bootstrap gcc we need to make a change to ../src/gcc-4.3.3/libgcc/config.host:
Change this line
... ... avr32-*-*) ;; ... ...to... ... avr32-*-*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o" ;; ... ...Save the file and begin the build:Now we need to make another change. But this time to ../build/bootstrap-gcc/gcc/libgcc.mvars:
Change this
to
Save the file and continue with the build:
glibc Headers - If binutils is not compatible with glibc this is where it will fail
Atmel binutils-2.20.1 patchset
Copy & paste the cotents below into a plain text file and save the file as patchset in atmel-patches/binutils-2.20.1 that you made previously.
return
Atmel gcc-4.3.3 patchset
Copy & paste the cotents below into a plain text file and save the file as patchset in atmel-patches/gcc-4.3.3 that you made previously.
return